using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace G15_Agent.Models.Mapping
{
    public class ChiTietHDKHMap : EntityTypeConfiguration<ChiTietHDKH>
    {
        public ChiTietHDKHMap()
        {
            // Primary Key
            this.HasKey(t => t.MaChiTietHD);

            // Properties
            this.Property(t => t.MaChiTietHD)
                .IsRequired()
                .HasMaxLength(15);

            this.Property(t => t.MaHD_KH)
                .HasMaxLength(15);

            this.Property(t => t.MaHD_NCC)
                .HasMaxLength(15);

            this.Property(t => t.ThongTinDV)
                .HasMaxLength(100);

            // Table & Column Mappings
            this.ToTable("ChiTietHDKH");
            this.Property(t => t.MaChiTietHD).HasColumnName("MaChiTietHD");
            this.Property(t => t.MaHD_KH).HasColumnName("MaHD_KH");
            this.Property(t => t.MaHD_NCC).HasColumnName("MaHD_NCC");
            this.Property(t => t.ThongTinDV).HasColumnName("ThongTinDV");
            this.Property(t => t.DonGia).HasColumnName("DonGia");
            this.Property(t => t.TrangThai).HasColumnName("TrangThai");

            // Relationships
            this.HasOptional(t => t.HoaDonNCC)
                .WithMany(t => t.ChiTietHDKHs)
                .HasForeignKey(d => d.MaHD_NCC);
            this.HasOptional(t => t.HoaDonKH)
                .WithMany(t => t.ChiTietHDKHs)
                .HasForeignKey(d => d.MaHD_KH);

        }
    }
}
